package com.sphd.emanu.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sphd.emanu.R;
import com.sphd.emanu.pojo.bank.TimeShowMoneyMessage;
import com.sphd.emanu.utils.StringFormatUtil;
import com.wzutils.L;
import com.wzutils.TimeUtils;

import java.text.ParseException;
import java.util.Calendar;
import java.util.List;

/**
 * @Author Hu
 * @Time 2017/7/11 --14:59.
 * @Email 87683202@qq.com
 */
public class TimeFragmentAdapter extends BaseQuickAdapter<TimeShowMoneyMessage.AccountPeriodListByDateBean, BaseViewHolder> {
    private boolean showIncome;//显示收入
    private boolean showExpend;//显示支出
    List<TimeShowMoneyMessage.AccountPeriodListByDateBean> data;
    private Context context;
    int state = 0;
    String beginDate, endDate;
    int showType = 0;

    public TimeFragmentAdapter(@LayoutRes int layoutResId, @Nullable List<TimeShowMoneyMessage.AccountPeriodListByDateBean> data,
                               boolean showIncome, boolean showExpend, Context context) {
        super(layoutResId, data);
        this.data = data;
        this.showIncome = showIncome;
        this.showExpend = showExpend;
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, TimeShowMoneyMessage.AccountPeriodListByDateBean item) {
        item.setShowType(showType);
        item.setSatate(state);


        // TODO: 2017/7/20 当state为4的时候需要对两个时间进行判断 其他的为定值 1、2 为日显示  3为月显示方式


        try {
            helper.setText(R.id.left_text, (showType == 3 ? TimeUtils.getMonth_Day(Calendar.getInstance(), item.getCreateDate(),
                    "yyyy-MM-dd") : showType == 2 ? TimeUtils.getMonth(Calendar.getInstance(), item.getCreateDate(), "yyyy-MM-dd") :
                    TimeUtils.getYear(Calendar.getInstance(), item.getCreateDate(), "yyyy-MM-dd")) +
                    "\n余额" + item.getBalance());
        } catch (ParseException e) {
            e.printStackTrace();
        }


        helper.setText(R.id.right_text,
                Html.fromHtml((showIncome ?
                        "<font color='#36b6a9' size='20'>" + "收入" + item.getCredit() : "") +
                        (showExpend ? "<br/><font color='red' size='20'>" + "支出" + item.getDebit()
                                : "")));
    }


    public void setSatate(int state, String beginDate, String endDate) {
        this.state = state;
        this.beginDate = beginDate;
        this.endDate = endDate;
        if (TimeUtils.isOneYear(beginDate, endDate)) {
            if (TimeUtils.isOneMonth(beginDate, endDate)) {
                showType = 3;
            } else {
                showType = 2;
            }
        } else {
            showType = 1;
        }

    }
}
